/**
 * @author Administrator
 * 多选择人员树
 */
var selectusertreecheckwin='',tree,selectusertreecheckidtager='',selectusertreechecknametager='';
function initselectusertreecheck(){
	 var datasort = new Ext.data.Store();
	
	 var userrecord = new Ext.data.Record([
	 	{name:'name',type:'string'},
	 	{name:'id',type:'int'}
	 ]);
	 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";
	 var url = Ext.get('basePath').getValue()+'tjsinfo/tjsoa/system/selectusertreecheck.do';
	 var load = new Ext.tree.TreeLoader({
	 	dataUrl:url
	 });
	 var root = new Ext.tree.AsyncTreeNode({
	 	id:'0',
	 	text:'天津利达粮油有限公司'
	 })
	 tree = new Ext.tree.TreePanel({
	 		x:0,
	 		y:0,	
        	autoScroll: true,
        	animate: true,
        	containerScroll: true,
        	border: true,
	        loader:load,	 
	        anchor:'100% 100%'
	    });
	tree.setRootNode(root); 
	tree.on('checkchange', function(node, checked) {  
		if(node.isExpanded()){
			node.collapse();
		}
		node.on('expand',function(){
			node.attributes.checked = checked;   
			node.eachChild(function(child) {   
				child.ui.toggleCheck(checked);   
				child.attributes.checked = checked;   
				child.fireEvent('checkchange', child, checked);   
			});  
		});
		node.expand();  
		 
	}, tree); 
	
	
	 tree.on('beforeload',function(node){ 
	     tree.loader.dataUrl=url+"?node="+node.id; //定义子节点的Loader 
	  }); 

	selectusertreecheckwin = new Ext.Window({
		layout:'absolute',
		title:'人员选择',
		width:520,
		height:500,
		modal:true,
		closeAction:'hide',
		items:[tree],
		buttonAlign:'right',
		buttons:[
		{
			text:'确认',
			handler:function(datasort){
				var checkarray = tree.getChecked(); 
				var username='',userid='';
				var indexname=1;
				for(var i = 0;i<tree.getChecked().length;i++)
				{
					
					if(!tree.getChecked()[i].attributes.isdepartment)
					{
						
						if(username.indexOf(','+tree.getChecked()[i].text+',') == -1 && tree.getChecked()[i].text!= tree.getChecked()[0].text || username == ''){
							username+=tree.getChecked()[i].text+',';						
							userid+=tree.getChecked()[i].id+',';
						}
						
					}
				}
				$('#'+selectusertreecheckidtager).attr('value',userid);
				$('#'+selectusertreechecknametager).attr('value',username);
				selectusertreecheckwin.hide();
			}
		},{
			text:'取消',
			handler:function(){
				selectusertreecheckwin.hide();		
			}
		}]
		
	})
}

//显示窗体
function selectusertreecheckwinshow(id,name,node){
	selectusertreecheckidtager = id;
	selectusertreechecknametager = name;
	selectusertreecheckwin.show();	
	selectusertreecheckwin.findByType('treepanel')[0].root.expand();
	var rootnode_ = tree.getRootNode();
	/**rootnode_.eachChild(function(child) {   
		child.ui.toggleCheck(false);   
		child.attributes.checked = false;
		child.fireEvent('checkchange', child, false);   
	});**/			
}

